<?php
/**
 * Created by PhpStorm.
 * User: chniccs
 * Date: 2019-11-27
 * Time: 14:25
 */

namespace app\app\controller;


use app\constant\BillConst;
use app\model\AppUserBill;
use app\model\AppUserWallet;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;

class Wallet extends Base
{

    public function getIncome()
    {
        $uid = $this->userInfo['uid'];
        $where = ['uid' => $uid];
        $where = $this->addTid($where);
        $model = AppUserWallet::get($where);
        $data = $model->getData();
        try {
            $incomeToday = (new AppUserBill())->where($where)->where('source', '<', BillConst::INCOME_TYPE_REFUND)->whereTime('create_time', 'today')->field('sum(money) as money')->group('uid')->select();
            if (count($incomeToday) == 0) {
                $data['income_today'] = 0;
            } else {
                if ($incomeToday[0]['money'] == null) {
                    $data['income_today'] = 0;
                } else {
                    $data['income_today'] = $incomeToday[0]['money'];
                }

            }
        } catch (DataNotFoundException $e) {
        } catch (ModelNotFoundException $e) {
        } catch (DbException $e) {
        }
        return $this->buildSuccess($data);
    }

}